package selenium;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

public class test {

	public static void main(String[] args) {
		// 鍒涘缓涓�釜WebDriver瀹炰緥j-inputtext dlemail
		final WebDriver driver = new ChromeDriver();
		try {
			driver.get("http://dy.163.com/wemedia/login.html");
			Thread.sleep(3000);
			driver.findElement(By.className("j-inputtext dlemail")).sendKeys("aa3338444555@163.com");
			//driver.manage().window().maximize();
			//driver.findElement(By.id("loginEmail")).sendKeys("aa3338444555@163.com");
			//driver.findElement(By.id("loginEmail")).sendKeys("wqw5812@163.com");
			//driver.findElement(By.id("loginEmail")).sendKeys("eee3887766@163.com");
			//driver.findElement(By.id("loginEmail")).sendKeys("ttt888668@163.com");
/*			driver.findElement(By.id("loginPassword")).sendKeys("huang147258");
			driver.findElement(By.id("loginBtn")).click();
			driver.findElement(By.linkText("鎴戠殑瑙嗛")).click();
			for (int i = 0; i < 6; i++) {
				driver.findElement(By.linkText("鍙戣棰�)).click();
				driver.findElement(By.id("video-up")).sendKeys("D:\\360鏋侀�娴忚鍣ㄤ笅杞絓\涓�銆婄埗浜层�鍞卞摥鎵�湁鍚紬锛岃瘎濮旈煩绾㈡洿鏄壄澶存摝娉�mp4");
				driver.findElement(By.id("description")).sendKeys("灏忎紮涓�銆婄埗浜层�鍞卞摥浜嗚浼楋紝璇勫闊╃孩鏇存槸鎵ご鎿︽唱锛�);
				driver.findElement(By.id("form-tags-input")).sendKeys("鐖朵翰");
				Actions action = new Actions(driver);
				action.sendKeys(Keys.SPACE).perform();
				driver.findElement(By.id("form-tags-input")).sendKeys("闊╃孩");
				action.sendKeys(Keys.SPACE).perform();
				driver.findElement(By.id("form-tags-input")).sendKeys("璇勫");
				action.sendKeys(Keys.SPACE).perform();
				driver.findElement(By.id("form-tags-input")).sendKeys("鍚紬");
				action.sendKeys(Keys.SPACE).perform();
				driver.findElement(By.id("form-tags-input")).sendKeys("婕斿敱浼�);
				action.sendKeys(Keys.SPACE).perform();
				
				File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
			    try {
			      FileUtils.copyFile(srcFile,new File("d:\\hehe\\screenshot"+i+".png"));
			    } catch (IOException e) {
			      e.printStackTrace();
			    }
				
				driver.findElement(By.xpath("//button[@type='button']")).click();
				driver.findElement(By.linkText("闊充箰")).click();
				driver.findElement(By.xpath("(//button[@type='button'])[2]")).click();
				driver.findElement(By.linkText("婕斿敱浼�)).click();
				driver.findElement(By.xpath("//form[@id='videoPost']/div[2]/div[6]/div/ul/li/a/label")).click();
				WebDriverWait wait = new WebDriverWait(driver, 50);
				wait.until(new ExpectedCondition<WebElement>() {
					@Override
					public WebElement apply(WebDriver d) {
						WebElement ddElement = driver.findElement(By.xpath("//*[@id='auto']/ul/li[1]/input"));
						if (ddElement != null) {
							return ddElement;
						} else {
							return null;
						}
					}
				});
				driver.findElement(By.xpath("(//input[@name='_picUrl'])[5]")).click();
				driver.findElement(By.xpath("//*[@id='videoPost']/div[2]/div[7]/div/button")).click();
				WebElement e = (new WebDriverWait(driver, 50)).until(new ExpectedCondition<WebElement>() {
					@Override
					public WebElement apply(WebDriver arg0) {
						WebElement sDriver = driver
								.findElement(By.xpath("//*[@class='modal fade in']/div[2]/div/div[3]/button"));
						if (sDriver != null) {
							return sDriver;
						} else {
							return null;
						}
					}
				});
				driver.findElement(By.xpath("//*[@class='modal fade in']/div[2]/div/div[3]/button")).click();
			}
			driver.manage().deleteAllCookies();
			driver.get("http://dy.163.com/wemedia/login.html");*/
		} catch (Exception e) {
			e.printStackTrace();
		}
		 driver.quit();
	}

}
